import { _decorator, sys, v3 } from 'cc';
const { ccclass } = _decorator;

@ccclass('User')
export class User  {

    static move(survivalId:number, userId:number) {

        let data = JSON.parse(sys.localStorage.getItem('survivalId-' + survivalId));
        if (data == null) {
            data = {}
        }

        data["userId-" + userId] =  true
        sys.localStorage.setItem('survivalId-' + survivalId, JSON.stringify(data));
    }

    static moved(survivalId:number, userId:number):boolean {
        let data = JSON.parse(sys.localStorage.getItem('survivalId-' + survivalId));
        if (data == null) {
            return false
        }

        return data.hasOwnProperty("userId-" + userId)
    }

    static getId():number {
        return Number(sys.localStorage.getItem('id'))
    }

    static setId(id:number) {
        sys.localStorage.setItem('id', id + "");
    }

    static clear(survivalId:number) {
        sys.localStorage.removeItem('survivalId-' + survivalId);
    }
}

